package com.starview.star.compiler.wff;

import com.starview.platform.data.type.Location;
import com.starview.star.compiler.ast.Abstract;
import com.starview.star.compiler.ast.IAbstract;
import com.starview.star.compiler.ast.Name;
import com.starview.star.compiler.standard.StandardNames;
import com.starview.star.compiler.util.PrettyPrintDisplay;

@SuppressWarnings("serial")
public class WffIdentifierPtn implements WffOp
{

  @Override
  public applyMode apply(IAbstract term, IAbstract env[], Location loc, WffEngine engine)
  {
    if (Abstract.isParenTerm(term)) {
      term = Abstract.deParen(term);
      if (term instanceof Name && !StandardNames.isKeyword(term))
        return applyMode.validates;
      else
        return applyMode.notValidates;
    } else if (term instanceof Name && !StandardNames.isKeyword(term))
      return applyMode.validates;
    else
      return applyMode.notValidates;
  }

  @Override
  public void prettyPrint(PrettyPrintDisplay disp)
  {
    disp.append(StandardNames.WFF_IDENTIFIER);
  }

  @Override
  public String toString()
  {
    return StandardNames.WFF_IDENTIFIER;
  }

  @Override
  public long specificity()
  {
    return 0;
  }
}
